package com.easywan.util;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

public class DubboUtils {
	/**
	 * 将obj转换成字节码
	 * 现在支持类型
	 * 1.BufferedImage
	 * @param obj
	 * @return
	 */
	public static byte[] toBytes(Object obj){
		if(obj instanceof BufferedImage){
			BufferedImage buffer = (BufferedImage) obj;
			ByteArrayOutputStream out = new ByteArrayOutputStream();  
			try {
				ImageIO.write(buffer, "PNG", out);
			} catch (IOException e) {
				e.printStackTrace();
			}
			return out.toByteArray();
		}
		return null;
	}
}
